package cn.gzsxt.music.mapper;

import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public class PowerProvider {
	public String checkExistsPowerActionName(Map<String, Object> params) {
		StringBuilder sql = new StringBuilder();
		sql.append( "select * from tb_power where power_action = #{power_action}");
		
		//如果有power_id就拼接poiwer_id对应的sql语句
		if(StringUtils.isNotBlank((String)params.get("power_id"))) {
			sql.append(" and  power_id !=#{power_id}");
		}
		//select * from tb_power where power_action = #{power_action} and  power_id !=${power_id}
		return sql.toString();
	}
	
	
	public String getPowerByPowerActions(String role_action) {
		StringBuilder sql = new StringBuilder();
		sql.append("select * from tb_power where power_action in (");
		
		String[] power_actions = role_action.split(",");
		for (String power_action : power_actions) {
			sql.append("'");
			sql.append(power_action);
			sql.append("',");
		}
		//删除最后一个逗号
		sql.deleteCharAt(sql.length()-1);
		
		sql.append(")");
		
		return sql.toString();
	}
}
